IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('PaintingInsert') AND sysstat & 0xf = 4)
    DROP PROCEDURE [PaintingInsert]
GO
CREATE PROCEDURE [PaintingInsert]
(
    @PaintingId int = null output,
    @Title nvarchar(100),
    @PaintingNumber nvarchar(100),
    @Description nvarchar,
    @ImageUrl nvarchar,
    @Tags nvarchar,
    @Authorships nvarchar,
    @Subjects nvarchar,
    @CreateDate datetime,
    @UpdateDate datetime,
    @HandEnable bit,
    @PrinterEnable bit,
    @Frames int
)
AS
BEGIN
	SET NOCOUNT ON
	INSERT INTO [painting](
        [title],
        [painting_number],
        [description],
        [image_url],
        [tags],
        [authorships],
        [subjects],
        [create_date],
        [update_date],
        [hand_enable],
        [printer_enable],
        [frames]
	)
	VALUES(
        @Title,
        @PaintingNumber,
        @Description,
        @ImageUrl,
        @Tags,
        @Authorships,
        @Subjects,
        @CreateDate,
        @UpdateDate,
        @HandEnable,
        @PrinterEnable,
        @Frames
	)
	SELECT @PaintingId = SCOPE_IDENTITY()
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('PaintingUpdate') AND sysstat & 0xf = 4)
    DROP PROCEDURE [PaintingUpdate]
GO
CREATE PROCEDURE [PaintingUpdate]
(
	@PaintingId int,
    @Title nvarchar(100),
    @PaintingNumber nvarchar(100),
    @Description nvarchar(max),
    @ImageUrl nvarchar(max),
    @Tags nvarchar(max),
    @Authorships nvarchar(max),
    @Subjects nvarchar(max),
    @HandEnable bit,
    @PrinterEnable bit,
    @Frames int
)
AS
BEGIN
	
	UPDATE [painting]
	SET
        [title]=@Title,
        [painting_number]=@PaintingNumber,
        [description]=@Description,
        [image_url]=@ImageUrl,
        [tags]=@Tags,
        [authorships]=@Authorships,
        [subjects]=@Subjects,
        [update_date]=GetDate(),
        [hand_enable]=@HandEnable,
        [printer_enable]=@PrinterEnable,
        [frames]=@Frames
	WHERE
		[painting_id] = @PaintingId

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('PaintingDelete') AND sysstat & 0xf = 4)
    DROP PROCEDURE [PaintingDelete]
GO
CREATE PROCEDURE [PaintingDelete]
(
	@PaintingId int	
)
AS
BEGIN
	
	DELETE
	FROM [painting]
    WHERE
		[painting_id] = @PaintingId
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('PaintingSelectOne') AND sysstat & 0xf = 4)
    DROP PROCEDURE [PaintingSelectOne]
GO
CREATE PROCEDURE [PaintingSelectOne]
(
	@PaintingId int
)
AS
BEGIN
	SET NOCOUNT ON	
	SELECT
		*
	FROM [painting] (NOLOCK)
	WHERE
		([painting_id] = @PaintingId)

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('PaintingSelectAll') AND sysstat & 0xf = 4)
    DROP PROCEDURE [PaintingSelectAll]
GO

CREATE PROCEDURE [PaintingSelectAll]
AS
BEGIN

	SET NOCOUNT ON
	SELECT
		*
	FROM [painting] (NOLOCK)

END
GO
